package logic

import (
	"context"

	"xialou_platform/services/agent/rpc/agentClient"
	"xialou_platform/services/agent/rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type StoreTypeListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewStoreTypeListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StoreTypeListLogic {
	return &StoreTypeListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商家类型
func (l *StoreTypeListLogic) StoreTypeList(in *agentClient.PlatformParam) (*agentClient.StoreTypeListResp, error) {
	tpList, err := l.svcCtx.StoreTypeModel.FindListByPlatform(l.ctx, in.Platform)
	if err != nil {
		return nil, err
	}

	list := make([]*agentClient.StoreType, 0)
	for _, storeType := range tpList {
		temp := &agentClient.StoreType{
			Id:              storeType.Id,
			Name:            storeType.Name,
			Platform:        storeType.Platform,
			StoreTypeId:     storeType.StoreTypeId,
			StoreTypeName:   storeType.StoreTypeName,
			DelFlag:         storeType.DelFlag,
			IndustryLicense: storeType.IndustryLicense,
		}
		list = append(list, temp)
	}

	return &agentClient.StoreTypeListResp{
		List: list,
	}, nil
}
